using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using DAL;
using Utility;
using SlimeeLibrary;
using FreeTextBoxControls;

public partial class Admin_sanphamthem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        ddl_Loai.DataSource = tbloaisanphamBUS.GETAll();
        ddl_Loai.DataTextField = tbloaispDTOColumn.Tenloaisp.ToString();
        ddl_Loai.DataValueField = tbloaispDTOColumn.Maloaisp.ToString();
        ddl_Loai.DataBind();
        ddl_dn.DataSource = tbdoanhnghiepBUS.GETAll();
        ddl_dn.DataTextField = tbdoanhnghiepDTOColumn.Tendn.ToString();
        ddl_dn.DataValueField = tbdoanhnghiepDTOColumn.Madn.ToString();
        ddl_dn.DataBind();
        DropDownList1.DataSource = tbtrangthaiBUS.GETAll();
        DropDownList1.DataTextField = tbtrangthaiDTOColumn.Tentrangthai.ToString();
        DropDownList1.DataValueField = tbtrangthaiDTOColumn.Matrangthai.ToString();
        DropDownList1.DataBind();
        DropDownList2.DataSource = tbtinhthanhBUS.GETAll();
        DropDownList2.DataTextField = tbtinhthanhDTOColumn.Tentinhthanh.ToString();
        DropDownList2.DataValueField = tbtinhthanhDTOColumn.Matinhthanh.ToString();
        DropDownList2.DataBind();
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            tbsanphamDTO sp = new tbsanphamDTO();
            
            sp.Tensp = txt_Tensp.Text;
            sp.Dacdiem = fr_dacdiem.Text;
            sp.Thongtin = fre_thongtin.Text;
            sp.Thoathuan = fre_thoathuan.Text;
            sp.Giaban = float.Parse(txt_giaban.Text.ToString());
            sp.Soluongmax = int.Parse(txt_soluongmax.Text.ToString());
            sp.Maloaisp = int.Parse(ddl_Loai.SelectedValue);
            sp.Ngaybatdau = DatePicker1.SelectedDate;
            sp.Ngayketthuc = DatePicker2.SelectedDate;
            sp.Madn = int.Parse(ddl_dn.SelectedValue);
            sp.Matinhthanh = int.Parse(DropDownList2.SelectedValue);
            sp.Giagoc = int.Parse(txt_gia.Text.ToString());
            sp.Soluongdaban = int.Parse(txt_soluong.Text.ToString());
            sp.Giatrisudung = float.Parse(txt_giatrithuc.Text);
            sp.Chietkhau = int.Parse(txt_chietkhau.Text.ToString());
            sp.Matrangthai = int.Parse(DropDownList1.SelectedValue);
            sp.Masp = tbsanphamBUS.Insert(sp);
            Session["idsp"] = sp.Masp.ToString();            
            Response.Redirect("themhinhanh.aspx");
        }
        catch(Exception f)
        { 
        }
    }
}
